package cn.lcc.utils.core.start;

import cn.lcc.utils.core.NettyServer;
import cn.lcc.utils.core.config.NettyConfig;
import cn.lcc.utils.handler.WatchNettyServer;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

@Slf4j
@Configurable
@Component
@AllArgsConstructor
public class NettyStarterOnApplicationEvent implements ApplicationListener<ApplicationStartedEvent> {

    private NettyConfig nettyConfig;

    @Override
    public void onApplicationEvent(ApplicationStartedEvent event) {
        NettyServer nettyServer = event.getApplicationContext().getBean(WatchNettyServer.class);
        if (!nettyServer.start()) {
            log.error("---------------watch Server 服务器启动失败---------------");
        }
        log.info(" netty start success ",nettyConfig.getPort());
    }
}
